//index.js
//获取应用实例
var app = getApp();
var _openid = app.getOpenId();
var WxParse = require('../../wxParse/wxParse.js');

Page({
  data: {
    parkingInfo:[],
    parkingId:"",
    orderId:""
  },
  //事件处理函数
  swiperchange: function(e) {
       this.setData({  
        swiperCurrent: e.detail.current  
    })  
  },

  onLoad: function (e) {

    this.setData({
      parkingId:e.id
    })
    wx.showLoading();
    var that = this;
    console.log("预定车位" + _openid);
    wx.request({
      url: app.globalData.domain + app.globalData.subDomain+'/parking/detail?',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        openid: _openid,
        id: e.id
      },
      success: function(res) {
        var parkingInfo = [];
        wx.hideLoading();
        if (res.data.obj.length == 0) {
          that.setData({
            loadingMoreHidden: false,
          });
          return;
        }
        parkingInfo.push(res.data.obj);
     
        that.setData({
          parkingInfo: parkingInfo,
        });
        }
    })
  },

  bookParking: function () {
      this.modalcnt();
  },

  modalcnt: function () {
    var bookParkingId = this.data.parkingId;
    var CarNumber = "jb888";
    var that = this;
    wx.request({
      url: app.globalData.domain + app.globalData.subDomain +'/parking/bookingParking?',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        openid: _openid,
        parkingID: bookParkingId,
        friendCarNumber: CarNumber
      },
      success: function (res) {
        console.log(res);
        if (res.data.code == 100) {
        var orderId = res.data.obj.id;
          wx.showModal({
            title: '提示',
            content: '如果您非本小区/大厦业主, 保安可能会拒绝车辆进入,请谨慎操作.',
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')
                wx.navigateTo({
                  url: "/pages/payOrderDetail/index?id=" + orderId
                })
              } else if (res.cancel) {

              }
            }
          })
        }else{
          console.log(res);
        }

      }
    })
  },  
})
